package com.ficus.road.maintain.core.model;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * @author xiawen yang
 * @date 2021/11/18 下午5:06
 */
public class MyExcelConverter implements Converter<Integer> {

    //在java中的数据类型
    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    // 在excel中的数据类型
    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    // 将excel的数据类型转换为java的数据类型(读excel)
    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }

    // 将java的数据类型转换为excel的数据类型（写excel）
    @Override
    public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if (value.equals(1)) {
            return new CellData("是");
        } else {
            return new CellData("否");
        }
    }
}
